package com.kgc.util;

import com.kgc.service.OrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.connection.Message;
import org.springframework.data.redis.connection.MessageListener;

/**
 * @author :qinya
 * @PackageName:com.kgc.util
 * @ClassName: RedisKeyExpirationListener
 * @Description: TODO
 * @date : 2025/5/30,16:09
 */

public class RedisKeyExpirationListener implements MessageListener {

    @Autowired
    private OrderService orderService;

    @Override
    public void onMessage(Message message, byte[] pattern) {
        // 获取过期的键名
        String expiredKey = new String(message.getBody());
        // 关闭订单
        orderService.closeOrder(expiredKey);
        System.out.println("键过期：" + expiredKey);
    }
}
